home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / yoohoo.c < prev    next >
C/C++ Source or Header  |  1989-03-07  |  17KB  |  565 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                     BinkleyTerm "YooHoo" Processor                       */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  27. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  28. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  29. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  30. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /*    The Authors can be reached at the following addresses:                */
  34. /*                                                                          */
  35. /*    Robert C. Hartman                      Vincent E. Perriello           */
  36. /*    Spark Software                         VEP Software                   */
  37. /*    427-3 Amherst Street                   111 Carroll Street             */
  38. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  39. /*    Nashua, NH 03061                                                      */
  40. /*                                                                          */
  41. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  42. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  43. /*                                                                          */
  44. /*    Please feel free to contact us at any time to share your comments     */
  45. /*    about our software and/or licensing policies.                         */
  46. /*                                                                          */
  47. /*                                                                          */
  48. /*--------------------------------------------------------------------------*/
  49.  
  50. #include <stdio.h>
  51. #include <signal.h>
  52. #include <ctype.h>
  53. #include <conio.h>
  54. #include <string.h>
  55.  
  56. #define WAZOO_SECTION
  57. #define MATRIX_SECTION
  58. #define isBITBRAIN 0x1b
  59.  
  60. #include "com.h"
  61. #include "xfer.h"
  62. #include "zmodem.h"
  63. #include "keybd.h"
  64. #include "sbuf.h"
  65. #include "sched.h"
  66. #include "externs.h"
  67. #include "prototyp.h"
  68.  
  69. static int Send_Hello_Packet (int);
  70. static int Recv_Hello_Packet (void);
  71.  
  72. /*--------------------------------------------------------------------------*/
  73. /* YOOHOO SENDER    (used when I am the CALLING system)                     */
  74. /*--------------------------------------------------------------------------*/
  75. int YooHoo_Sender (void)
  76. {
  77.    char *sptr;
  78.  
  79.    if (un_attended && fullscreen)
  80.       {
  81.       sb_move (filewin, 2, 2);
  82.       sb_puts (filewin, "YooHoo");
  83.       sb_show ();
  84.       }
  85.    else
  86.       {
  87.       set_xy ("YooHoo ");
  88.       }
  89.  
  90.    if (!Send_Hello_Packet (1))
  91.       sptr = "No Send";
  92.  
  93.    else
  94.       {
  95.       if (TIMED_READ (30) == YOOHOO)
  96.          return Recv_Hello_Packet ();
  97.  
  98.       status_line ("!No YOOHOO/2U2");
  99.       sptr = IDUNNO_msg;
  100.       }
  101.  
  102.    message (sptr);
  103.    return (0);
  104. }
  105.  
  106. /*--------------------------------------------------------------------------*/
  107. /* YOOHOO RECEIVER  (Used when I am the CALLED system)                      */
  108. /*--------------------------------------------------------------------------*/
  109.  
  110. int YooHoo_Receiver (void)
  111. {
  112.    int i;
  113.    int c;
  114.  
  115.    if (un_attended && fullscreen)
  116.       {
  117.       sb_move (filewin, 2, 2);
  118.       sb_puts (filewin, "YooHoo");
  119.       sb_show ();
  120.       }
  121.    else
  122.       {
  123.       set_xy ("YooHoo ");
  124.       }
  125.  
  126.    if (!(i = Recv_Hello_Packet()))
  127.       return (0);
  128.  
  129.    for (i = 0; (CARRIER) && (i < 10); i++)
  130.       {
  131.       if ((c = TIMED_READ (10)) == ENQ)
  132.          return Send_Hello_Packet (0) ? 1 : (b_init (), 0);
  133.  
  134.       if (c > 0)
  135.          {
  136.          message (NULL);
  137.          cprintf ("[%x] ", c);
  138.          CLEAR_INBOUND ();
  139.          }
  140.  
  141.       SENDBYTE (YOOHOO);
  142.       }
  143.  
  144.    hup = 1;
  145.    message (FUBAR_msg);
  146.    b_init ();
  147.    return (0);
  148.  
  149. }                                                /* YooHoo Receiver */
  150.  
  151. /*--------------------------------------------------------------------------*/
  152. /* SEND HELLO PACKET                                                        */
  153. /*--------------------------------------------------------------------------*/
  154. static int Send_Hello_Packet (Sender)
  155. int Sender;
  156. {
  157.    int i;
  158.    struct _Hello Hello;
  159.    byte *sptr;
  160.    long response_timer;
  161.    word crc;
  162.    word num_errs = 0;
  163.  
  164.    /*--------------------------------------------------------------------*/
  165.    /* Setup HELLO structure                                              */
  166.    /*--------------------------------------------------------------------*/
  167.    memset ((char *) &Hello, 0, sizeof (struct _Hello));
  168.  
  169.    Hello.signal = 'o';
  170.    Hello.hello_version = 1;
  171.  
  172.    Hello.product = isBITBRAIN;
  173.    Hello.product_maj = BINK_MAJVERSION;
  174.    Hello.product_min = BINK_MINVERSION;
  175.  
  176.    strncpy (Hello.my_name, system_name, 58);
  177.    Hello.my_name[58] = '\0';
  178.  
  179.    strncpy (Hello.sysop, sysop, 19);
  180.    Hello.sysop[19] = '\0';
  181.  
  182.    Hello.my_zone = alias[assumed].Zone;
  183.    if ((pvtnet >= 0) && (Sender) &&
  184.        ((called_zone == alias[assumed].Zone) || (called_zone == 0)) &&
  185.        (called_net == boss_net) && (called_node == boss_node))
  186.       {
  187.       Hello.my_net = boss_net;
  188.       Hello.my_node = boss_node;
  189.       Hello.my_point = alias[assumed].Node;
  190.       }
  191.    else
  192.       {
  193.       Hello.my_net = alias[assumed].Net;
  194.       Hello.my_node = alias[assumed].Node;
  195.       }
  196.  
  197.    Hello.capabilities = (no_zapzed) ? 0 : ZED_ZAPPER;
  198.    Hello.capabilities |= Y_DIETIFNA;
  199. #ifdef JANUS
  200.    if (janus_baud >= cur_baud)
  201.       Hello.capabilities |= DOES_IANUS;
  202. #endif
  203.  
  204.    if (n_getpassword (remote_zone, remote_net, remote_node))
  205.       {
  206.       strncpy (Hello.my_password, remote_password, 8);
  207.       }
  208.  
  209.    if ((matrix_mask & TAKE_REQ) &&
  210.        ((!Sender) || (on_our_nickel)))
  211.       Hello.capabilities |= WZ_FREQ;
  212.  
  213.    /*--------------------------------------------------------------------*/
  214.    /* Disable handshaking and ^C/^K handling                             */
  215.    /*--------------------------------------------------------------------*/
  216.    XON_DISABLE ();
  217.  
  218.    /*--------------------------------------------------------------------*/
  219.    /* Send the packet.                                                   */
  220.    /* Load outbound buffer quickly, and get modem busy sending.          */
  221.    /*--------------------------------------------------------------------*/
  222.  
  223. xmit_packet:
  224.  
  225.    SENDBYTE (0x1f);
  226.  
  227.    sptr = (char *) (&Hello);
  228.    SENDCHARS (sptr, 128, 1);
  229.  
  230.    /*--------------------------------------------------------------------*/
  231.    /* Calculate CRC while modem is sending its buffer                    */
  232.    /*--------------------------------------------------------------------*/
  233.    for (crc = i = 0; i < 128; i++)
  234.       {
  235.       crc = xcrc (crc, (byte) sptr[i]);
  236.       }
  237.  
  238.    CLEAR_INBOUND ();
  239.  
  240.    SENDBYTE ((unsigned char) (crc >> 8));
  241.    SENDBYTE ((unsigned char) (crc & 0xff));
  242.  
  243.    response_timer = timerset (4000);
  244.  
  245.    while (!timeup(response_timer) && CARRIER)
  246.       {
  247.       if (!CHAR_AVAIL ())
  248.          {
  249.          if (got_ESC ())
  250.             {
  251.             DTR_OFF ();
  252.             sptr  = KBD_msg;
  253.             goto no_response;
  254.             }
  255.      time_release ();
  256.          continue;
  257.      }     
  258.  
  259.       switch (i = TIMED_READ (0))
  260.          {
  261.          case ACK:
  262.             return (1);
  263.  
  264.          case '?':
  265.             message ("drats");
  266.  
  267.          case ENQ:
  268.             if (++num_errs == 10)
  269.                 {
  270.                 sptr = FUBAR_msg;
  271.                 goto no_response;
  272.                 }
  273.             goto xmit_packet;
  274.  
  275.          default:
  276.             if (i > 0)                   /* Could just be line noise */
  277.                {
  278. /*             cprintf ("[%x] ", i);*/
  279.                }
  280.             break;
  281.          }
  282.       }
  283.  
  284.    if (!CARRIER)
  285.       sptr = CARRIER_msg;
  286.    else
  287.       sptr  = TIME_msg;
  288.  
  289. no_response:
  290.  
  291.    message (sptr);
  292.    return (0);
  293.  
  294. }                                                /* Send Hello */
  295.  
  296.  
  297. /*--------------------------------------------------------------------------*/
  298. /* RECEIVE HELLO PACKET                                                     */
  299. /*--------------------------------------------------------------------------*/
  300. static int Recv_Hello_Packet (void)
  301. {
  302.    int i;
  303.    int c;
  304.    struct _Hello Hello;
  305.    byte *sptr;
  306.    byte num_errs = 0;
  307.    word crc;
  308.    word lsb;
  309.    word msb;
  310.    long master_timeout, hello_timeout;
  311.    char junkbuff[128];
  312.  
  313.    hup = 0;
  314.    sptr = NULL;
  315.  
  316.    /*--------------------------------------------------------------------*/
  317.    /* Clean up any mess that may be around                               */
  318.    /*--------------------------------------------------------------------*/
  319.    CLEAR_OUTBOUND ();
  320.    CLEAR_INBOUND ();
  321.    XON_DISABLE ();
  322.  
  323.    /*--------------------------------------------------------------------*/
  324.    /* Get the Hello structure                                            */
  325.    /*--------------------------------------------------------------------*/
  326.  
  327. /* big_pause (1);  */                           /* Wait for quiet. */
  328.    
  329.    if (un_attended && fullscreen)
  330.       {
  331.       sb_move (filewin, 2, 2);
  332.       sb_puts (filewin, "YooHoo/2U2");
  333.       sb_show ();
  334.       }
  335.    else
  336.       {
  337.       set_xy ("YooHoo/2U2 ");
  338.       }
  339.  
  340.    SENDBYTE (ENQ);                               /* Let the other system know
  341.                                                   * we heard YooHoo. */
  342.  
  343.    master_timeout = timerset (12000);        /* No more than 2 mins! */
  344.  
  345. watch_for_header:
  346.  
  347.    while (1)
  348.       {
  349.       if (sptr)
  350.          {
  351.          message (sptr);
  352.          sptr = NULL;
  353.          }
  354.  
  355.       if ((c = TIMED_READ (20)) == 0x1f)
  356.          break;
  357.  
  358.       if (got_ESC ())
  359.          {
  360.          sptr = KBD_msg;
  361.          goto receive_failed;
  362.          }
  363.  
  364.       if (!CARRIER)
  365.          {
  366.          sptr = CARRIER_msg;
  367.          goto receive_failed;
  368.          }
  369.  
  370.       if (timeup(master_timeout))
  371.          goto timeout;
  372.  
  373.       if (c >= 0)                               /* noise? */
  374.          {
  375.          hello_timeout = timerset (1000);       /* Look for up to 10 secs  */
  376.          while (((c = PEEKBYTE ()) >= 0) && (c != 0x1f) && (CARRIER))
  377.             {
  378.             if (timeup(hello_timeout))
  379.                break;
  380.             MODEM_IN ();                        /* Eat non-YooHoo chars    */
  381.             }
  382.  
  383.          if (c != 0x1f)                         /* If we didn't get YooHoo */
  384.             {
  385.             CLEAR_INBOUND ();                   /* Throw out what we have  */
  386.             SENDBYTE (ENQ);                     /* Start over with ENQ     */
  387.             }
  388.          }
  389.  
  390.       }                         /* while */
  391.  
  392.  
  393. /*receive_packet:*/
  394.  
  395.    sptr = (char *) (&Hello);
  396.  
  397.    hello_timeout = timerset (3000);
  398.  
  399.    for (i = 0, crc = 0; i < 128; i++)
  400.       {
  401.  
  402.       while (PEEKBYTE () < 0)
  403.          {
  404.          if (timeup (master_timeout) || timeup (hello_timeout))
  405.             goto timeout;
  406.         
  407.          if (got_ESC ())
  408.             {
  409.             sptr = KBD_msg;
  410.             goto receive_failed;
  411.             }
  412.  
  413.          if (!CARRIER)
  414.             {
  415.             sptr = CARRIER_msg;
  416.             goto receive_failed;
  417.             }
  418.  
  419.          time_release ();
  420.      }
  421.  
  422.       c = TIMED_READ (0);
  423.  
  424.       sptr[i] = (char) c;
  425.       crc = xcrc (crc, (byte) c);
  426.       }
  427.  
  428.    if (!CARRIER)
  429.       {
  430.       sptr = CARRIER_msg;
  431.       goto receive_failed;
  432.       }
  433.  
  434.    if (((msb = TIMED_READ (10)) < 0) || ((lsb = TIMED_READ (10)) < 0))
  435.       {
  436.       sptr = SHRT_msg;
  437.       goto hello_error;
  438.       }
  439.  
  440.    if (((msb << 8) | lsb) == crc)
  441.       goto process_hello;
  442.  
  443.    sptr = CRC_msg;
  444.  
  445. hello_error:
  446.  
  447.    if (timeup(master_timeout))
  448.       goto timeout;
  449.  
  450.    if ((num_errs++) > 10)
  451.       {
  452.       sptr = FUBAR_msg;
  453.       goto receive_failed;
  454.       }
  455.  
  456.    CLEAR_INBOUND ();
  457.    SENDBYTE ('?');
  458.    goto watch_for_header;
  459.  
  460. process_hello:
  461.  
  462.    Hello.my_name[42] = '\0';
  463.    Hello.sysop[19] = '\0';
  464.    remote_zone = Hello.my_zone;
  465.    remote_net = Hello.my_net;
  466.    remote_node = Hello.my_node;
  467.    remote_point = Hello.my_point;
  468.  
  469.    remote_capabilities = (Hello.capabilities) | Y_DIETIFNA;
  470.  
  471.    if (nodefind (remote_zone, remote_net, remote_node, 0) && !remote_zone)
  472.       remote_zone = found_zone;
  473.  
  474.    sprintf (junkbuff, "*%s (%u:%u/%u.%u)",
  475.             Hello.my_name,
  476.             remote_zone,
  477.             remote_net,
  478.             remote_node,
  479.             remote_point);
  480.    status_line (junkbuff);
  481.  
  482.    if ((pvtnet >= 0) &&
  483.        ((remote_zone == alias[assumed].Zone) || (remote_zone == 0)) &&
  484.        (remote_net == boss_net) && (remote_node == boss_node) &&
  485.        (remote_point > 0))
  486.       {
  487.       remote_net = pvtnet;
  488.       remote_node = Hello.my_point;
  489.       remote_point = 0;
  490.       }
  491.  
  492.    switch (Hello.product)
  493.       {
  494.       case isBITBRAIN:
  495.       case isFIDO:
  496.       case isSPARK:
  497.       case isSEA:
  498.       case isHENK:
  499.       case isTABBIE:
  500.       case isWOLF:
  501.       case isQMM:
  502.       case isFD:
  503.       case isTERUS:
  504.       case isCYGNUS:
  505.       case isGSPOINT:
  506.       case isBGMAIL:
  507.       case isCROSSBOW:
  508.       case isDBRIDGE:
  509.       case isDAISY:
  510.       case isTHEBOX:
  511.          status_line ("*Remote uses %s Version %d.%02d",
  512.              prodcode[Hello.product], Hello.product_maj, Hello.product_min);
  513.          break;
  514.  
  515.       case isOPUS:
  516.          status_line ("*Remote Uses Opus Version %d.%02d", Hello.product_maj,
  517.                       (Hello.product_min == 48) ? 0 : Hello.product_min);
  518.          break;
  519.       default:
  520.          status_line ("*Remote Uses Program '%02x' Version %d.%02d",
  521.                       Hello.product, Hello.product_maj, Hello.product_min);
  522.          break;
  523.       }
  524.  
  525.    if (Hello.sysop[0])
  526.       status_line (":Sysop: %s", Hello.sysop);
  527.  
  528.    if (remote_point > 0)
  529.       {
  530.       remote_point = 0;
  531.       remote_node = -1;
  532.       }
  533.  
  534.    if (n_getpassword (remote_zone, remote_net, remote_node))
  535.       {
  536.       if (n_password (Hello.my_password, remote_password))
  537.          {
  538.          DTR_OFF ();                            /* He'll never get it right */
  539.          timer (2);                             /* Wait two secs */
  540.          sptr = NULL;                           /* Already logged something */
  541.          goto receive_failed;
  542.          }
  543.       }
  544.  
  545.    CLEAR_INBOUND ();
  546.  
  547.    SENDBYTE (ACK);
  548.    SENDBYTE (YOOHOO);
  549.  
  550.    return (1);
  551.  
  552. timeout:
  553.  
  554.    sptr = TIME_msg;
  555.  
  556. receive_failed:
  557.  
  558.    hup = 1;
  559.    message (sptr);
  560.    b_init ();
  561.    return (0);
  562. }                                               /* Recv Hello */
  563.  
  564. /* END OF FILE: yoohoo.c */
  565.